<?php
/*************************************************

视频主模型 - the 
Author: WangHuabin <17-5-31>

*************************************************/
namespace Home\Model;
use Think\Model\RelationModel;
class VideoModel extends RelationModel {
    //查询多条数据 不分页
    public function get_all($map,$field="*",$order){
        $map['status']=0;
        $data = $this->where($map)->field($field)->order($order)->select();
        return $data;
    }   
     //查询多条数据 带分页
    public function get_all_page($map,$field="*",$order,$page,$pagenum){
        $map['status']=0;
        $data = $this->where($map)->field($field)->order($order)->limit($page,$pagenum)->select();
        return $data;
    }    


    //查询单数据
    public function get_one($map,$order="add_time desc"){
        $map['status']=0;
        $data = $this->where($map)->order($order)->find();
        return $data;
    }

    //更新
    public function edit($map,$data){
        $r = $this->where($map)->save($data);
        return $r;
    }

    //添加
    public function add($data){
        $data =M('Video')->data($data)->add();
        return $data;
    }

    //统计
    public function count($map=''){
        $map['status']=0;
        $count = M('Video')->where($map)->count();
        return $count;
    }

    //关联仓库阅读量排序
    public function jion_play($map='',$order='',$field='*',$start='0',$end='999999999'){
        $map['jg_video.status']=0;
        $data = M('Video')->join('jg_video_house ON jg_video.video_id = jg_video_house.id')->where($map)->order($order)->field($field)->limit($start,$end)->select();
        // echo  M('Video')->_sql();
        return $data;
    }

    //关联仓库阅读量排序
    public function jion_play_one($map='',$field='*'){
        //$map['jg_video.status']=0;
        $data = M('Video')->join('jg_video_house ON jg_video.video_id = jg_video_house.id')->where($map)->field($field)->find();
        // echo  M('Video')->_sql();
        return $data;
    }


    //评论+1
    function set_comments_int($map){
        $r= $this->where($map)->setInc('count_comments');
        return $r;
    }



    public function get_alls($map,$limit){
        $data = $this->where($map)->limit($limit)->select();
        return $data;
    }   

}